package com.qf.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sunyamei
 * @version V1.0
 * @Project springmvc_Demo
 * @Package com.qf.service.Impl
 * @Description:
 * @Date 2022/7/15 17:01
 */
@Service
public class UserServiceImpl implements UserService {

   @Autowired
   private UserDao userDao;

    /**
     * 查找所有
     * @return
     */
    @Override
    public List<User> findAll() {

        return userDao.findAll();
    }

    /**
     * 分页
     * @param paheNum
     * @param pageSize
     * @return
     */
    @Override
    public Object findPage(Integer paheNum, Integer pageSize) {
       //查询之前引入分页插件
        PageHelper.startPage(paheNum, pageSize);
        //查询
        Page<User> page = userDao.findPage();
        //封装pageInfo
        PageInfo<User> pageInfo = new PageInfo<>(page);
        System.out.println(pageInfo);

        return pageInfo;
    }

    /**
     * 根据名字删除
     * @param name
     */
    @Override
    public void deleteByName(String name) {
        userDao.deleteByName(name);

    }

    /**
     * 添加
     * @param user
     */
    @Override
    public void add(User user) {
        userDao.add(user);
    }
    /**
     * 根据id修改
     * @param user
     */

    @Override
    public void updateById(User user) {
        userDao.updateById(user);
    }

    /**
     * 根据ID删除
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        userDao.deleteById(id);
    }


}
